from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.


class User(AbstractUser):
    """
    用户模型类
    """
    class Meta:
        db_table = 'tb_users'
        verbose_name = '用户'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class Score(models.Model):
    client = models.CharField(verbose_name='客户端号', max_length=16, unique=True)
    score = models.IntegerField(verbose_name='分数', default=0,
                                validators=[MaxValueValidator(10000000), MinValueValidator(1)])

    def __str__(self):
        return self.client

    class Meta:
        verbose_name = '分数登记表'


class Rank(models.Model):
    """
    名次
    """
    c_id = models.OneToOneField(Score, on_delete=models.CASCADE,primary_key=True,)
    rank = models.IntegerField(verbose_name='名次', validators=[MinValueValidator(1)])

